package stark.app.frame.netframe;

import android.view.View;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import stark.app.R;
import stark.app.databinding.ActivityNetFrameBinding;
import stark.common.basic.base.BaseActivity;

public class NetFrameActivity extends BaseActivity<DetailViewModel, ActivityNetFrameBinding> {

    private DetailAdapter mAdapter;
    private RecyclerView mRvNews;
    private View mLastView;

    @Override
    protected int onCreate() {
        return R.layout.activity_net_frame;
    }

    @Override
    protected void initView() {
        mRvNews = mDataBinding.rv;
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        mAdapter = new DetailAdapter();
        mRvNews.setLayoutManager(manager);
        mRvNews.setAdapter(mAdapter);
    }

    @Override
    protected void initData() {
        mDataBinding.setModel(this);
        mDataBinding.setLifecycleOwner(this);
        mViewModel.getDetail().observe(this, new Observer<DetailBean>() {
            @Override
            public void onChanged(DetailBean detailBean) {
                mAdapter.setNewData(detailBean.data.list);
            }
        });
        mViewModel.requestData();
    }

    @Override
    protected DetailViewModel initViewModel() {
        return new ViewModelProvider(this).get(DetailViewModel.class);
    }
    @Override
    protected void showError(Object obj) {

    }
}